package com.example.knowman.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.knowman.entity.staffList;
import com.example.knowman.mapper.StaffListMapper;
import com.example.knowman.service.IStaffListService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class StaffListServiceImpl extends ServiceImpl<StaffListMapper, staffList> implements IStaffListService {

    private final StaffListMapper staffListMapper;
    public StaffListServiceImpl(StaffListMapper StaffListMapper) {
//        this.iTable1Service = iTable1Service;
        this.staffListMapper = StaffListMapper;
    }


    @Override
    public String getStaffName(String staffCode) {
        try{
            staffList res=this.lambdaQuery().select().eq(staffList::getStaffCode,staffCode).one();
            return res.getStaffName();
        }catch (Exception e){
            return null;
        }


    }

    @Override
    public List<staffList> listByDeptName(String ArchDeptName) {


        List<staffList>    list=this.lambdaQuery()
                    .select()
                    .eq(ArchDeptName != null && !ArchDeptName.isEmpty(),staffList::getArchDeptName,ArchDeptName)
                    .list();




        return list;
    }

    @Override
    public Map<String, String> getIdAndName() {
        return this.lambdaQuery().select().list().stream()
                .collect(Collectors.toMap(staffList::getStaffCode, staffList::getStaffName));
    }

    @Override
    public List<staffList> listByDeptCode(String archDeptCode) {
        return this.lambdaQuery().select().eq(staffList::getArchDeptCode,archDeptCode).list();
    }

    @Override
    public Map<String, staffList> getAll() {
        return this.lambdaQuery().select().list().stream()
                .collect(Collectors.toMap(staffList::getStaffCode, Function.identity()));
    }


}
